package com.itheima.tcp02;

import java.io.*;
import java.net.Socket;

/*
发送端
 */
public class Client {

    public static void main(String[] args) throws IOException {
        Socket cs = new Socket("127.0.0.1", 8888);

        OutputStream os = cs.getOutputStream();
        //需要一个 字符->字节的桥梁
        String s="你好啊";
        //把字符流转换成字节流  字节流 发送数据
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os));
        //发送
        writer.write(s);
        //刷新缓冲流
        writer.flush();
        //给对方一个结束标记
        cs.shutdownOutput();
        //接收服务器给我们的响应
        InputStream is = cs.getInputStream();
        // 想看的是汉字
        //需要字节->字符的桥梁
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        String result;
        while ((result=reader.readLine())!=null){
            System.out.println(result);
        }
        //释放资源
        reader.close();
        writer.close();
        cs.close();
    }
}
